#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright @ 2014 OPS, Qunar Inc. (qunar.com)
#
# Author: tingfang.bao <tingfang.bao@qunar.com>
# DateTime: 15-3-10 下午4:50
from database import db_session, metadata
import sqlalchemy as sa
from sqlalchemy.orm import mapper


# 显示了手动映射的方法
class User(object):
    # 这样，就可以直接从model中获取query了
    query = db_session.query_property()

    def __init__(self, username, email):
        self.username = username
        self.email = email

    def __repr__(self):
        return '<User %s>' % self.username


users = sa.Table("users", metadata,
                 sa.Column("id", sa.Integer, primary_key=True),
                 sa.Column('username', sa.String),
                 sa.Column("email", sa.String))

mapper(User, users)
